home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers3.zip / ES3210.ASM < prev    next >
Assembly Source File  |  1992-02-07  |  9KB  |  376 lines

  1. version    equ    0
  2. ;History:254,1
  3.  
  4. ;  The following people have contributed to this code: David Horne, Eric
  5. ;  Henderson, and Bob Clements.
  6.  
  7. ;  Copyright, 1988-1992, Russell Nelson, Crynwr Software
  8.  
  9. ;   This program is free software; you can redistribute it and/or modify
  10. ;   it under the terms of the GNU General Public License as published by
  11. ;   the Free Software Foundation, version 1.
  12. ;
  13. ;   This program is distributed in the hope that it will be useful,
  14. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ;   GNU General Public License for more details.
  17. ;
  18. ;   You should have received a copy of the GNU General Public License
  19. ;   along with this program; if not, write to the Free Software
  20. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.     include    defs.asm
  23.  
  24.     .286
  25.  
  26. code    segment    word public
  27.     assume    cs:code, ds:code
  28.  
  29. ;*****************************************************************************
  30. ;
  31. ;    es3210 controller board offsets
  32. ;    IO port definition (BASE in io_addr)
  33. ;*****************************************************************************
  34. NE_RESET    equ    04h        ;board control bits.
  35. EBASE        equ    10h
  36. EN_OFF        equ    20h
  37. NE_DATAPORT    equ    60h        ; es3210 Port Window.
  38.  
  39.     include    8390.inc
  40.  
  41. ; Shared memory management parameters
  42.  
  43. SM_TSTART_PG    equ    000h    ; First page of TX buffer
  44. SM_RSTART_PG    equ    006h    ; Starting page of RX ring
  45. SM_RSTOP_PG    equ    040h    ; Last page +1 of RX ring
  46.  
  47. ram_enable    macro
  48.     endm
  49.  
  50. reset_8390    macro
  51.     loadport
  52.     setport    NE_RESET
  53.     mov    al,4            ;reset the board.
  54.     out    dx,al
  55.     longpause
  56.     mov    al,1            ;unreset the board.
  57.     out    dx,al
  58.  
  59.     endm
  60.  
  61. terminate_board    macro
  62.     endm
  63.  
  64.     public    int_no, io_addr, mem_base
  65. int_no        db    2,0,0,0        ;must be four bytes long for get_number.
  66. io_addr        dw    0300h,0        ; I/O address for card
  67. mem_base    dw    00000h,0    ; Shared memory addr
  68.  
  69.     public    driver_class, driver_type, driver_name, driver_function, parameter_list
  70. driver_class    db    BLUEBOOK, IEEE8023, 0        ;from the packet spec
  71. driver_type    dw    54        ;from the packet spec
  72. driver_name    db    'es3210',0    ;name of the driver.
  73. driver_function    db    2
  74. parameter_list    label    byte
  75.     db    1    ;major rev of packet driver
  76.     db    9    ;minor rev of packet driver
  77.     db    14    ;length of parameter list
  78.     db    EADDR_LEN    ;length of MAC-layer address
  79.     dw    GIANT    ;MTU, including MAC headers
  80.     dw    MAX_MULTICAST * EADDR_LEN    ;buffer size of multicast addrs
  81.     dw    0    ;(# of back-to-back MTU rcvs) - 1
  82.     dw    0    ;(# of successive xmits) - 1
  83. int_num    dw    0    ;Interrupt # to hook for post-EOI
  84.             ;processing, 0 == none,
  85.  
  86. is_186        db    0
  87.  
  88.     include    movemem.asm
  89.  
  90. ;
  91. ;    Block input routine
  92. ;    CX = byte count, es:di = buffer location, ax = buffer address
  93.  
  94.     public    block_input
  95. block_input:
  96.     push    ds
  97.     assume    ds:nothing
  98.     mov    ds,mem_base        ; ds:si points at first byte to move
  99.     mov    si,ax
  100.  
  101.     add    ax,cx            ; Find the end of this frame.
  102.     cmp    ah,byte ptr cs:sm_rstop_ptr ; Over the top of the ring?
  103.     jb    rcopy_one_piece        ; Go move it
  104.  
  105. rcopy_wrap:
  106. ; Copy in two pieces due to buffer wraparound.
  107.     mov    ah,byte ptr cs:sm_rstop_ptr ; Compute length of first part
  108.     xor    al,al
  109.     sub    ax,si            ;  as all of the pages up to wrap point
  110.     sub    cx,ax            ; Move the rest in second part
  111.     push    cx            ; Save count of second part
  112.     mov    cx,ax            ; Count for first move
  113.     shr    cx,2            ; convert byte count to dword count
  114.     db    0f3h, 066h, 0a5h    ;rep movsd
  115.     mov    si,SM_RSTART_PG*256    ; Offset to start of first receive page
  116.     pop    cx            ; Bytes left to move
  117. rcopy_one_piece:
  118. ;transfer all complete dwords.
  119.     push    cx
  120.     shr    cx,2            ; convert byte count to dword count
  121.     db    0f3h, 066h, 0a5h    ;rep movsd
  122.     pop    cx
  123.  
  124. ;now take take of any trailing words and/or bytes.
  125.     db    066h, 0adh        ;lodsd
  126.  
  127.     test    cx,2
  128.     je    rcopy_one_word
  129.     stosw
  130.     db    066h, 0c1h, 0e8h, 010h    ;shr    eax,16
  131. rcopy_one_word:
  132.  
  133.     test    cx,1
  134.     je    rcopy_one_byte
  135.     stosb
  136. rcopy_one_byte:
  137.  
  138.     pop    ds
  139.     ret
  140.  
  141.  
  142.     push    ax        ; save buffer address
  143.     loadport
  144.     setport EN_CCMD
  145.     pause_
  146.     mov    al,ENC_NODMA+ENC_PAGE0+ENC_START
  147.     out    dx,al
  148.     setport    EN0_RCNTLO    ; remote byte count 0
  149.     pause_
  150.     mov    al,cl
  151.     out    dx,al
  152.     setport    EN0_RCNTHI
  153.     pause_
  154.     mov    al,ch
  155.     out    dx,al
  156.     pop    ax        ; get our page back
  157.     setport    EN0_RSARLO
  158.     pause_
  159.     out    dx,al        ; set as hi address
  160.     setport    EN0_RSARHI
  161.     pause_
  162.     mov    al,ah
  163.     out    dx,al
  164.     setport EN_CCMD
  165.     pause_
  166.     mov    al,ENC_RREAD+ENC_START    ; read and start
  167.     out    dx,al
  168.     setport    NE_DATAPORT
  169.     pause_
  170.     inc    cx        ; make even
  171.     shr    cx,1        ; word count
  172.     rep    insw
  173.     ret
  174. ;
  175. ;    Block output routine
  176. ;    CX = byte count, ds:si = buffer location, ax = buffer address
  177.  
  178. block_output:
  179.     assume    ds:nothing
  180.  
  181.     mov    es,mem_base        ; Set up ES:DI at the shared RAM
  182.     mov    di,ax            ; ..
  183.     add    cx,3            ;round up to next highest dword.
  184.     shr    cx,2
  185.     db    0f3h, 066h, 0a5h    ;rep movsd
  186.     clc
  187.     ret
  188.  
  189.     push    ax        ; save buffer address
  190.     add    cx,3        ; round up to nearest dword.
  191.     and    cx,0fffch
  192.     loadport
  193.     setport EN_CCMD
  194.     pause_
  195.     mov    al,ENC_NODMA+ENC_START
  196.     out    dx,al        ; stop & clear the chip
  197.     setport    EN0_RCNTLO    ; remote byte count 0
  198.     pause_
  199.     mov    al,cl
  200.     out    dx,al
  201.     setport    EN0_RCNTHI
  202.     pause_
  203.     mov    al,ch
  204.     out    dx,al
  205.     pop    ax        ; get our page back
  206.     setport    EN0_RSARLO
  207.     pause_
  208.     out    dx,al        ; set as lo address
  209.     setport    EN0_RSARHI
  210.     pause_
  211.     mov    al,ah
  212.     out    dx,al
  213.     setport EN_CCMD
  214.     pause_
  215.     mov    al,ENC_RWRITE+ENC_START    ; write and start
  216.     out    dx,al
  217.     setport    NE_DATAPORT
  218.     pause_
  219.     shr    cx,2        ; dword count
  220.     db 0f3h, 066h, 06fh    ;rep    outsd
  221.  
  222.     mov    cx,0
  223.     setport    EN0_ISR
  224. tx_check_rdc:
  225.     in    al,dx
  226.     test    al,ENISR_RDC    ; dma done ???
  227.     jnz    tx_start
  228.     loop    tx_check_rdc
  229.     stc
  230.     ret
  231. tx_start:
  232.     clc
  233.     ret
  234.  
  235.  
  236.     include    8390.asm
  237.  
  238.     public    usage_msg
  239. usage_msg    db    "usage: es3210 [-n] [-d] [-w] <packet_int_no> <int_level> <io_addr> <mem_base>",CR,LF,'$'
  240. no_board_msg    db    "No es3210 detected.",CR,LF,'$'
  241. io_addr_funny_msg    label    byte
  242.         db    "No es3210 detected, continuing anyway.",CR,LF,'$'
  243.  
  244.     public    copyright_msg
  245. copyright_msg    db    "Packet driver for es3210, version "
  246.         db    '0'+(majver / 10),'0'+(majver mod 10),".",'0'+version,".",'0'+dp8390_version,CR,LF,'$'
  247.  
  248. int_no_name    db    "Interrupt number ",'$'
  249. io_addr_name    db    "I/O port ",'$'
  250. mem_base_name    db    "Memory address ",'$'
  251.  
  252.     extrn    set_recv_isr: near
  253.  
  254. ;enter with si -> argument string, di -> word to store.
  255. ;if there is no number, don't change the number.
  256.     extrn    get_number: near
  257.  
  258. ;enter with dx -> name of word, di -> dword to print.
  259.     extrn    print_number: near
  260.  
  261.     public    parse_args
  262. parse_args:
  263. ;exit with nc if all went well, cy otherwise.
  264.     mov    di,offset int_no
  265.     call    get_number
  266.     mov    di,offset io_addr
  267.     call    get_number
  268.     mov    di,offset mem_base
  269.     call    get_number
  270.  
  271.     cmp    io_addr,-1        ;Did they ask for auto-detect?
  272.     je    find_board
  273.  
  274.     call    detect_board        ;no, just verify its existance.
  275.     je    find_board_found
  276.  
  277.     mov    dx,offset io_addr_funny_msg
  278.     mov    ah,9
  279.     int    21h
  280.  
  281.     jmp    find_board_found
  282.  
  283. find_board:
  284.     mov    io_addr,0c80h        ;Search for the Ethernet address.
  285.     mov    io_addr+2,0
  286. find_board_0:
  287.     call    detect_board
  288.     je    find_board_found
  289. find_board_again:
  290.     add    io_addr,1000h        ;not at this port, try another.
  291.     jnc    find_board_0
  292.  
  293.     mov    dx,offset no_board_msg    ;Tell them that we can't find it.
  294.     mov    ah,9
  295.     int    21h
  296.  
  297.     stc
  298.     ret
  299. find_board_found:
  300.     clc
  301.     ret
  302.  
  303.     extrn    etopen_diagn: byte
  304.  
  305. init_card:
  306. ;get the board data. This is (16) bytes starting at remote
  307. ;dma address 0. Put it in a buffer called board_data.
  308.     assume    ds:code
  309.  
  310.     or    endcfg,ENDCFG_WTS
  311.  
  312.     push    ds
  313.     pop    es        ; set es to ds
  314.     mov    di,offset board_data
  315.  
  316.     loadport            ; Get our Ethernet address base.
  317.     setport    EBASE
  318.     mov    cx,EADDR_LEN
  319. read_address_1:
  320.     insb                ; get a byte of the eprom address
  321.     inc    dx            ; next register
  322.     loop    read_address_1        ; go back for rest
  323.  
  324.     push    ds              ; Copy from card's address to current address
  325.     pop     es
  326.  
  327.     mov si, offset board_data    ; address is at start
  328.     mov di, offset curr_hw_addr
  329.     mov cx, EADDR_LEN       ; Copy one address length
  330.     rep     movsb           ; ..
  331.  
  332.     ret
  333.  
  334.     public    print_parameters
  335. print_parameters:
  336. ;echo our command-line parameters
  337.     mov    di,offset int_no
  338.     mov    dx,offset int_no_name
  339.     call    print_number
  340.     mov    di,offset io_addr
  341.     mov    dx,offset io_addr_name
  342.     call    print_number
  343.     mov    di,offset mem_base
  344.     mov    dx,offset mem_base_name
  345.     call    print_number
  346.     ret
  347.  
  348. detect_board:
  349. ;test to see if a board is located at io_addr.
  350. ;return nz if not.
  351.     loadport
  352.     setport    EBASE
  353.     in    al,dx            ;Check for Interlan's prefix word.
  354.     cmp    al,2
  355.     jne    detect_board_exit
  356.  
  357.     setport    EBASE+1
  358.     in    al,dx
  359.     cmp    al,7
  360.     jne    detect_board_exit
  361.  
  362.     setport    EBASE+EADDR_LEN        ;first byte following should be 0
  363.     in    al,dx
  364.     cmp    al,0
  365.     jne    detect_board_exit
  366.  
  367.     setport    EBASE+EADDR_LEN+1    ;second byte should be 55h
  368.     in    al,dx
  369.     cmp    al,55h
  370. detect_board_exit:
  371.     ret
  372.  
  373. code    ends
  374.  
  375.     end
  376.